<template>
  <div class="page-article" v-if="model">
    <!-- 头部 -->
    <div class="d-flex px-2 py-3 article-herder">
      <div class="iconfont icon-back color" @click="out"></div>
      <div class="d-flex flex-1 fs-md mx-2 text-ellipsis color"><strong>{{ model.title }}</strong></div>
      <div class="text-grey fs-xs">2020-03-02</div>
    </div>
    <!-- 详情 -->
    <div v-html="model.body" class="px-3 article-body p fs-xl"></div>
  </div>
</template>

<script>
import dayjs from 'dayjs'
export default {
  props: {
    id: { required: true },
  },
  filters: {
    date(val) {
      return dayjs(val).format('YYYY-MM-DD')
    }
  },
  data() {
    return {
      model: {}
    }
  },
  methods: {
    async fetch() {
      const res = await this.$http.get(`/strategy/${this.id}`)
      res.data.map(v => {
        return v.map(v1 => {
          if (typeof(v1) === 'object') {
            this.model = v1
          } 
        })
      })
    },
    out() {
      this.$router.go(-1)
    }
  },
  created() {
    this.fetch()
  },
  watch: {
    id() {
      this.fetch()
    }
  }
}
</script>

<style lang="scss">
.page-article {
  .article-herder {
    border-bottom: 1px solid #d4d9de;
  }
  .color {
    color: #4394e4;
  }
  .article-body {
    img {
      max-width: 100%;
      height: auto;
    }
  }
}
</style>